
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<span style="font-size:18px;">
<html>
<head>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" type="text/css" href="weddingPhotography/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="weddingPhotography/css/commonly-used-show.css" />
    <script type="text/javascript" src="weddingPhotography/js/jquery.min.js"></script>
    <script type="text/javascript" src="weddingPhotography/js/bootstrap.js" ></script>


    <link rel="stylesheet" type="text/css" href="weddingPhotography/css/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="weddingPhotography/css/modal.css" />
    <script type="text/javascript" src="weddingPhotography/js/modal.js" ></script>

    <title>我的文件夹</title>

    <style type="text/css">
        td, th {
            text-align: center;
        }
    </style>

</head>

<body class="mybody">

 <jsp:include page="theTopMenuUser.jsp" />


 <div class="container-fluid">
    <div class="row">


        <div class="col-md-12">
            <div class="col-md-12">
                    <div class="panel panel-primary">
                        <div class="panel-body">


<div>
    <h3 style="text-align: center">文件夹信息列表</h3>
    <table border="1" class="table table-bordered table-hover">
        <thead>
        <tr class="success">
            <th>序号</th>
            <th>文件夹名称</th>
            <th>创建时间</th>
            <th>操作</th>
        </tr>
        </thead>

        <tbody id="tbody-result">
        </tbody>

        <tr><td style="border-style: none;">&nbsp&nbsp;</td></tr>

        <tr>
            <td colspan="4" align="center"><a class="btn btn-primary" href="${pageContext.request.contextPath}/addMenus">添加文件夹</a></td>
        </tr>



    </table>


    <div class="text-center">
            <label id="user_null" style="color: red"></label>
        </div>

</div>

                        </div>
                    </div>
            </div>
        </div>



    </div>

 </div>






<script type="text/javascript">
    var userdt = JSON.parse(sessionStorage.getItem("user"));
    var userNull = document.getElementById("user_null");
    if (userdt.result.userName != null){
        $("#usname").text(userdt.result.userName);
    }else {
        $("#usname").text(userdt.result.userLoginName);
    }


    window.onload = function(){
        photoInfo();
    }

    function photoInfo(){
        var postUrl = "${pageContext.request.contextPath}/member/selectMenusIdAll";

        var str = {
            "userId": userdt.result.id
        };

        $.ajax({
            type:"post",
            url:postUrl,
            headers: {
                "Content-Type":"application/json"
            },
            data:JSON.stringify(str),
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function(data){
                if (data.status == "0"){
                    userNull.innerHTML = data.msg;
                }else {
                    var strtab = "";
                    //清空表格数据
                    $("#tbody-result").html("");


                    var conter = 1;
                    for (var i = 0; i < data.result.length; i++) {

                        strtab = "<tr>" + "<td>" + conter + "</td>"
                            + "<td>" + data.result[i].moduleName + "</td>"
                            + "<td>" + data.result[i].createTime + "</td>"
                            + "<td>" + "<a class=\"btn btn-default btn-sm\" href=${pageContext.request.contextPath}/updateMenus?id=" + data.result[i].id + ">修改 </a> "
                            + "<a class=\"btn btn-default btn-sm\" href=\"#\" onclick=\"deleteMenus('" + data.result[i].id + "," + data.result[i].moduleName + "')\">删除</a>" + "</td>"
                            + "</tr>";
                        $("#tbody-result").append(strtab);//将数据追加进表格

                        conter++;
                    }
                }

            },
            error:function(xhr,state,errorThrown){
                //alert("发生网络错误，错误码为：" + xhr.status)
                location.href = "${pageContext.request.contextPath}/error";
            }
        });
    }

    function deleteMenus(datees){
        var mModal2 = new mModal({
            top: "40vh",
            content: "你确定要删除此项？",
            confirm: function () {
                deleteMenus1(datees);
                mModal2.close();
            },
            cancel: function () {
            }
        });

        mModal2.renderDom();

    }

    function deleteMenus1(datees){
        var arr = datees.split(",");
        var id = arr[0];
        var menu = arr[1];
        var postUrl = "${pageContext.request.contextPath}/member/deleteMenusByPrimaryKey";
        var str = {
            "id": id
        };
        $.ajax({
            type:"post",
            url:postUrl,
            headers: {
                "Content-Type":"application/json"
            },
            data:JSON.stringify(str),
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function(data){
                if (data.status == "0"){
                    alert("删除文件夹出错")
                }else {
                    deletPhoto(menu);
                }

            },
            error:function(xhr,state,errorThrown){
                //alert("发生网络错误，错误码为：" + xhr.status)
                location.href = "${pageContext.request.contextPath}/error";
            }
        });
    }

    function deletPhoto(moduleName){
        var postUrl = "${pageContext.request.contextPath}/member/deleteUserPicture";
        var str = {
            "userId": userdt.result.id,
            "moduleName": moduleName
        };
        $.ajax({
            type:"post",
            url:postUrl,
            headers: {
                "Content-Type":"application/json"
            },
            data:JSON.stringify(str),
            contentType: "application/json; charset=utf-8",
            dataType:"json",
            success:function(data){
                if (data.status == "0"){
                    alert("删除文件夹下图片出错")
                }else {
                    location.href = "${pageContext.request.contextPath}/myFolder";
                }

            },
            error:function(xhr,state,errorThrown){
                //alert("发生网络错误，错误码为：" + xhr.status)
                location.href = "${pageContext.request.contextPath}/error";
            }
        });
    }

</script>

</body>
</html>
</span>